package capsulation;

public class Man {
    //1.合理隐藏
    private String name;
    private int age;



    //2.合理暴露
    // 公开的setter和getter方法
    public void setName(String name){
        this.name = name;//为名字赋值
    }

    public String getName(){
        return name;//返回名字
    }

    public void setAge(int age){
        //判断年龄是否合法然后赋值
        if (age > 0){
            this.age = age;
        }
        else{
            System.out.println("年龄不合法");
        }
    }

    public int getAge(){
        return age;
    }
}
